package org.vectrics.user.web.struts;

import org.apache.ecs.html.A;
import org.apache.ecs.html.IMG;
import org.apache.ecs.html.Input;
import org.vectrics.common.html.Cell;
import org.vectrics.common.html.Row;
import org.vectrics.common.html.Table;
import org.vectrics.common.view.HtmlForm;
import org.vectrics.common.view.HtmlFormEditRow;
import org.vectrics.struts.VectricsTagSupport;

public class PersonSearchFormTag extends VectricsTagSupport {

	private static final long serialVersionUID = 6603902029919862409L;
	
	private String personId = null;
	
	@Override
	protected String makeStartTag() {
		HtmlForm form = new HtmlForm(this.getRequest(), "userSearchForm", this.getPhrase("phrase.person.search.information"));
		
		form.setAction("/admin/user/nameSearch");

		
		HtmlFormEditRow formRow = (HtmlFormEditRow)form.addEditForParam(this.getPhrase("prompt.last.name"), "lastName", false); 
		Input lastNameEdit = formRow.getEditBox();
		lastNameEdit.setOnChange("findMatches();");
		
		formRow = (HtmlFormEditRow)form.addEditForParam(this.getPhrase("prompt.first.name"), "firstName", false);
		Input firstNameEdit = formRow.getEditBox();
		firstNameEdit.setOnChange("findMatches();");

		formRow = (HtmlFormEditRow)form.addEditForParam(this.getPhrase("prompt.phone.or.fax"), "phoneNumber", false);
		Input phoneEdit = formRow.getEditBox();
		phoneEdit.setOnChange("findMatches();");

		formRow = (HtmlFormEditRow)form.addEditForParam(this.getPhrase("prompt.city"), "city", false);
		Input cityEdit = formRow.getEditBox();
		cityEdit.setOnChange("findMatches();");

		formRow = (HtmlFormEditRow)form.addEditForParam(this.getPhrase("prompt.state"), "state", false);
		Input stateEdit = formRow.getEditBox();
		stateEdit.setOnChange("findMatches();");
		
		StringBuffer html = new StringBuffer();
		html.append(form.toString());

		Table table = new Table();
		Row row = table.addRow();
		Cell cell = row.addCell();
		A cancelLink = new A();
    	cancelLink.setHref("");
    	cancelLink.setOnClick("cancel(); return false");
    	IMG buttonImage = new IMG();
    	buttonImage.setSrc("/hrs-intranet/dynagraphic/button.jpg?code=button.param&caption=" +
    			this.getPhrase("button.cancel"));
    	buttonImage.setAlt(this.getPhrase("button.cancel"));
    	buttonImage.setBorder(0);
    	cancelLink.addElement(buttonImage);
    	cell.addElement(cancelLink.toString());
		

		cell = row.addCell();
		A pickLink = new A();
    	pickLink.setHref("#");
    	pickLink.setOnClick("findMatches(); return false");
    	buttonImage = new IMG();
    	buttonImage.setSrc("/hrs-intranet/dynagraphic/button.jpg?code=button.param&caption=" +
    			this.getPhrase("phrase.search"));
    	buttonImage.setAlt("Search");
    	buttonImage.setBorder(0);
    	pickLink.addElement(buttonImage);
    	cell.addElement(pickLink.toString());
    	
    	html.append(table.toString());
		return(html.toString());
	}

	public String getPersonId() {
		return personId;
	}

	public void setPersonId(String personId) {
		this.personId = personId;
	}


}
